//
//  WQIntelligenceWeatherCell.m
//  WisdomQuestor
//
//  Created by 纪景城 on 2024/12/18.
//

#import "WQIntelligenceWeatherCell.h"

@implementation WQIntelligenceWeatherCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.clipsToBounds = YES;
        self.backgroundColor = UIColor.clearColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubviews:[NSArray arrayWithObjects:self.weatherBackImageView, self.weatherTypeImageVIew, self.weatherNumberLabel, self.weatherDescLabel, self.airQualityDescLabel, self.outdoorDescLabel, nil]];
        [self fragmentUI_ViewSet];
    }
    return self;
}

#pragma mark ------- Lazy Methods -------

- (void)fragmentUI_ViewSet {
    [self.weatherBackImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView.mas_left).offset(kFragmemtFloat(12));
        make.right.equalTo(self.contentView.mas_right).offset(-kFragmemtFloat(12));
        make.top.bottom.equalTo(self.contentView);
    }];
    [self.weatherTypeImageVIew mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.weatherBackImageView.mas_left).offset(kFragmemtFloat(20));
        make.top.equalTo(self.weatherBackImageView.mas_top).offset(kFragmemtFloat(16));
        make.size.mas_equalTo(kSizzleKapadate(40, 34));
    }];
    [self.weatherNumberLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.weatherTypeImageVIew.mas_right).offset(kFragmemtFloat(12));
        make.bottom.equalTo(self.weatherTypeImageVIew);
    }];
    [self.weatherDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.weatherBackImageView.mas_left).offset(kFragmemtFloat(26));
        make.bottom.equalTo(self.weatherBackImageView.mas_bottom).offset(-kFragmemtFloat(8));
    }];
    [self.airQualityDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.weatherBackImageView);
        make.bottom.equalTo(self.weatherDescLabel);
    }];
    [self.outdoorDescLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.weatherBackImageView.mas_right).offset(-kFragmemtFloat(54));
        make.bottom.equalTo(self.weatherDescLabel);
    }];
}

- (UIImageView *)weatherBackImageView {
    if (!_weatherBackImageView) {
        _weatherBackImageView = [[UIImageView alloc] initWithImage:kImageName(@"home_weather_bg")];
    }
    return _weatherBackImageView;
}

- (UIImageView *)weatherTypeImageVIew {
    if (!_weatherTypeImageVIew) {
        _weatherTypeImageVIew = [[UIImageView alloc] initWithImage:kImageName(@"home_weatherType_duoyun")];
    }
    return _weatherTypeImageVIew;
}

- (UILabel *)weatherNumberLabel {
    if (!_weatherNumberLabel) {
        _weatherNumberLabel = [UILabel initWithTextColor:k_Color_222222 weight:UIFontWeightMedium size:16];
        NSString *weaString = @"16°C";
        NSMutableAttributedString *rightAS = [[NSMutableAttributedString alloc] initWithString:weaString];
        [rightAS addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:kFragmemtFloat(28) weight:UIFontWeightMedium]} range:NSMakeRange(0, weaString.length - 2)];
        _weatherNumberLabel.attributedText = rightAS;
    }
    return _weatherNumberLabel;
}

- (UILabel *)weatherDescLabel {
    if (!_weatherDescLabel) {
        _weatherDescLabel = [UILabel initWithTextColor:k_Color_666666 weight:UIFontWeightMedium size:10];
        _weatherDescLabel.numberOfLines = 0;
        NSString *weaString = @"优\n室外PM2.5";
        NSMutableAttributedString *rightAS = [[NSMutableAttributedString alloc] initWithString:weaString];
        [rightAS addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:kFragmemtFloat(12) weight:UIFontWeightMedium]} range:NSMakeRange(0, 1)];
        
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineSpacing = 5;  // 设置行间距为 10 个单位
        [rightAS addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, rightAS.length)];
        
        _weatherDescLabel.attributedText = rightAS;
    }
    return _weatherDescLabel;
}

- (UILabel *)airQualityDescLabel {
    if (!_airQualityDescLabel) {
        _airQualityDescLabel = [UILabel initWithTextColor:k_Color_666666 weight:UIFontWeightMedium size:10];
        _airQualityDescLabel.numberOfLines = 0;
        NSString *weaString = @"优\n室外空气质量";
        NSMutableAttributedString *rightAS = [[NSMutableAttributedString alloc] initWithString:weaString];
        [rightAS addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:kFragmemtFloat(12) weight:UIFontWeightMedium]} range:NSMakeRange(0, 1)];
        
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineSpacing = 5;  // 设置行间距为 10 个单位
        [rightAS addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, rightAS.length)];
        
        _airQualityDescLabel.attributedText = rightAS;
    }
    return _airQualityDescLabel;
}

- (UILabel *)outdoorDescLabel {
    if (!_outdoorDescLabel) {
        _outdoorDescLabel = [UILabel initWithTextColor:k_Color_666666 weight:UIFontWeightMedium size:10];
        _outdoorDescLabel.numberOfLines = 0;
        NSString *weaString = @"74.0%\n室外湿度";
        NSMutableAttributedString *rightAS = [[NSMutableAttributedString alloc] initWithString:weaString];
        [rightAS addAttributes:@{NSFontAttributeName: [UIFont systemFontOfSize:kFragmemtFloat(12) weight:UIFontWeightMedium]} range:NSMakeRange(0, 5)];
        
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineSpacing = 5;  // 设置行间距为 10 个单位
        [rightAS addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, rightAS.length)];
        
        _outdoorDescLabel.attributedText = rightAS;
    }
    return _outdoorDescLabel;
}

@end
